package com.toKnow.service.impl;

import com.toKnow.mapper.ArticleMapper;
import com.toKnow.mapper.CreatorMapper;
import com.toKnow.mapper.SourceMapper;
import com.toKnow.model.entity.Article;
import com.toKnow.model.entity.CreatorData;
import com.toKnow.service.CreatorService;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class CreatorServiceImpl implements CreatorService {
    @Autowired
    CreatorMapper creatorMapper;
    @Autowired
    ArticleMapper articleMapper;
    @Autowired
    SourceMapper sourceMapper;
    public List<Integer> changeToInteger(List<CreatorData> creatorDataList){
        List<Integer> ans=new ArrayList<>();
        int a[]=new int[30];
        Date startDate = new Date();
        startDate.setHours(0);startDate.setMinutes(0);startDate.setSeconds(0);
        startDate=DateUtils.addDays(startDate,-30);
        for (int i=0;i<30;i++) a[i]=0;
        for (CreatorData creatorData : creatorDataList) {
            a[(int)((creatorData.getDate().getTime()-startDate.getTime())/24/3600/1000)]=creatorData.getNumber();
        }
        for (int i=0;i<30;i++){
            ans.add(a[i]);
        }
        return ans;
    }
    @Override
    public List<Integer> getDataArticleRead(Integer authorId) {
        return changeToInteger(creatorMapper.dataArticleRead(authorId));
    }
    @Override
    public List<Integer> getDataArticleLike(Integer authorId) {
        return changeToInteger(creatorMapper.dataArticleLike(authorId));
    }

    @Override
    public List<Integer> getDataSourceLike(Integer authorId) {
        return changeToInteger(creatorMapper.dataSourceLike(authorId));
    }

    @Override
    public List<Integer> getDataArticleCollect(Integer authorId) {
        return changeToInteger(creatorMapper.dataArticleCollect(authorId));
    }

    @Override
    public List<Integer> getDataSourceDownload(Integer authorId) {
        return changeToInteger(creatorMapper.dataSourceDownload(authorId));
    }

    @Override
    public List<Integer> getDataSourceCollect(Integer authorId) {
        return changeToInteger(creatorMapper.dataSourceCollect(authorId));
    }

    @Override
    public List<Integer> getDataArticleComment(Integer authorId) {
        return changeToInteger(creatorMapper.dataArticleComment(authorId));
    }

    @Override
    public List<Integer> getDataSourceComment(Integer authorId) {
        return changeToInteger(creatorMapper.dataSourceComment(authorId));
    }

    public List<Integer> getDataFans(Integer userId) {
        return changeToInteger(creatorMapper.dataFans(userId));
    }
}
